package com.yangfei.mystudy1020;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.yangfei.mystudy1020.activity.MaskDrawActivity;
import com.yangfei.mystudy1020.activity.SocketActivity;
import com.yangfei.mystudy1020.activity.SocketServerActivity;

public class MainActivity extends AppCompatActivity {

    Class[] mTestActivity={
            MaskDrawActivity.class,
            SocketActivity.class,
            SocketServerActivity.class
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        for(Class cls:mTestActivity){
            addNewTestActivity(cls, (ViewGroup) findViewById(R.id.ll_main));
        }

    }

    private void addNewTestActivity(final Class cls,ViewGroup root){
        Button btn = new Button(this);
        root.addView(btn);
        btn.setText(cls.getSimpleName());
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent in = new Intent(MainActivity.this, cls);
                MainActivity.this.startActivity(in);
            }
        });
    }

}
